﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Shapes;
using System.Windows.Threading;

namespace FasterWPF
{
    public static class Helpers
    {
        public enum ItemTextRows
        {
            OneRowOfText = 1,
            TwoRowsOfText = 2
        }

        public enum SetFocus
        {
            None=0,
            Delayed=1,
            Immediate=2
        }

        public static MouseButtonEventArgs GetMouseClickArgs()
        {
            return new MouseButtonEventArgs(Mouse.PrimaryDevice, 100, MouseButton.Left);
        }

        public static T Cast<T>(this object source)
        {
            return (T)source;
        }

        public static void IfNotNull(string parm1, string parm2, Action actionIfTrue)
        {
            if (parm1 != null && parm2 != null)
            {
                actionIfTrue();
            }
        }

        //source: http://www.mgbrown.com/PermaLink68.aspx
        public static string Left(string text, int length)
        {
            if (length < 0)
                throw new ArgumentOutOfRangeException("length", length, "length must be > 0");
            else if (length == 0 || text.Length == 0)
                return "";
            else if (text.Length <= length)
                return text;
            else
                return text.Substring(0, length);
        }
    }
}
